package epimarket.beans;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import epimarket.helper.Utils;

@SuppressWarnings("serial")
public class Compte implements Serializable {	
	private int id;
	private int id_adresse_postale;
	private String nom;
	private String prenom;
	private String mdp;
	private String mail;
	private String telephone;
	private String anniversaire;
	private int sexe;
	
	public Compte() {
		this.id = -1;
		this.id_adresse_postale = -1;
		this.nom = "";
		this.prenom = "";
		this.mdp = "";
		this.mail = "";
		this.telephone = "";
		this.anniversaire = "";
		this.sexe = -1;
	}
	
	public String toString() {
		String str = "";
		str += "id_user = " + this.id + "<br />";
		str += "id_adresse = " + this.id_adresse_postale + "<br />";
		str += "nom = " + this.nom + "<br />";
		str += "prenom = " + this.prenom + "<br />";
		str += "mdp = " + this.mdp + "<br />";
		str += "mail = " + this.mail + "<br />";
		str += "telephone = " + this.telephone + "<br />";
		str += "anniversaire = " + this.anniversaire + "<br />";
		str += "sexe = " + this.sexe + "<br />";
		return str;
	}
	
	public static boolean isEmailAdress(String email){
		Pattern p = Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
		Matcher m = p.matcher(email.toUpperCase());
		return m.matches();
	}
	
	public boolean validate(String verif) {
		if (!nom.equals("") && !prenom.equals("") && !mdp.equals("") && mdp.equals(verif) && !mail.equals("") && isEmailAdress(mail) &&
			!telephone.equals("") && Utils.isAlphanumeric(telephone) && !anniversaire.equals("") &&
			Utils.isDate(anniversaire) && (sexe == 0 || sexe == 1)) {
			return true;
		} else {
			return false;
		}
	}

	/*
	 * Getter et Setter
	 */
	
	public int getId() {
		return id;
	}

	public void setId(int idd) {
		this.id = idd;
	}

	public int getId_adresse() {
		return id_adresse_postale;
	}

	public void setId_adresse(int id_adresse) {
		this.id_adresse_postale = id_adresse;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public String getMdp() {
		return mdp;
	}

	public void setMdp(String mdp) {
		this.mdp = mdp;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getAnniversaire() {
		return anniversaire;
	}

	public void setAnniversaire(String anniversaire) {
		this.anniversaire = anniversaire;
	}

	public int getSexe() {
		return sexe;
	}

	public void setSexe(int sexe) {
		this.sexe = sexe;
	}
}
